﻿using FBroSharp;
using FBroSharp.DataType;
using FBroSharp.Lib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace URL请求测试_带浏览器环境
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //开始创建浏览器
            FBroSharpWindowsInfo windows_info = new FBroSharpWindowsInfo
            {
                parent_window = this.Handle,
                x = 0,
                y = 0,
                width = ClientSize.Width,
                height = ClientSize.Height,
                window_name = "FBrowserCEF3Lib创建URL请求测试"
            };

            //创建浏览器事件回调类
            BrowserEvent browser_event = new BrowserEvent();

            if (FBroSharpControl.CreatBrowser("https://bbs.fbrowser.site", windows_info, default, default, default, browser_event, default))
                Console.WriteLine("true");
        }


        private void Form1_Resize(object sender, EventArgs e)
        {
            if(BrowserEvent.mainbrowser_.IsValid)
                BrowserEvent.mainbrowser_.MoveWindow(0, 0, this.ClientSize.Width, this.ClientSize.Height, true);

        }

private void 创建URL请求ToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (BrowserEvent.mainbrowser_.IsValid)
    {
        FBroSharpRequest sharp_request = new FBroSharpRequest();
        sharp_request.SetURL("https://api.fbrowser.site:8443/");
        sharp_request.SetMethod("GET");

        //添加协议头，这里用list添加，只添加了一个UA
        List<FBroSharpStringMap> heard_list = new List<FBroSharpStringMap>();

        heard_list.Add(new FBroSharpStringMap
        {
            key = "User-Agent",
            value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.97 Safari/537.36 Core/1.116.438.400 QQBrowser/13.0.6071.400"
        });
        sharp_request.SetHeaderMap_Array(heard_list);

        // FBroSharpRequestContext sharp_request_context;
        URLEvent sharp_event = new URLEvent();
        BrowserEvent.mainbrowser_.GetMainFrame().CreateURLRequest(sharp_request, sharp_event, 123456);
    }
}

        private void 开发者工具ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserEvent.mainbrowser_.ShowDevTools("开发者工具", IntPtr.Zero, 0, 0, 1024, 720, default, default, default, default);
        }
    }
}
